package com.onec.service.channel.service.impl;

import com.onec.service.api.dto.request.channel.ChannelMerchantReq;
import com.onec.service.api.enums.StatusEnum;
import com.onec.service.channel.dao.ChannelMerchantBusinessRepository;
import com.onec.service.channel.entity.ChannelInfo;
import com.onec.service.channel.entity.ChannelMerchantBusiness;
import com.onec.service.channel.service.ChannelMerchantBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author onec
 * @see
 * @since 20200821
 */
@Service
public class ChannelMerchantBusinessServiceImpl implements ChannelMerchantBusinessService {


    @Autowired
    ChannelMerchantBusinessRepository channelMerchantBusinessRepository;

    @Override
    public ChannelMerchantBusiness create(ChannelInfo channelInfo, ChannelMerchantReq channelMerchantReq) {
        return null;
    }

    @Override
    public ChannelMerchantBusiness findByMerchantNoChannelIdBusinessNo(String merchantNo, long channelId, String businessNo) {
        return channelMerchantBusinessRepository.findByMerchantNoAndChannelIdAndBusinessNo(merchantNo, channelId, businessNo);
    }

    @Override
    public ChannelMerchantBusiness updateByMerchantNoBusinessNo(long channelId, String businessNo, StatusEnum statusEnum,
                                                                String merchantNo, String channelMerchantNo, String message) {
        ChannelMerchantBusiness channelMerchantBusiness = findByMerchantNoChannelIdBusinessNo(merchantNo, channelId, businessNo);
        channelMerchantBusiness.setStatus(statusEnum);
        channelMerchantBusiness.setRemarks(message);
        channelMerchantBusiness.setChannelMerchantNo(channelMerchantNo);
        return channelMerchantBusinessRepository.save(channelMerchantBusiness);
    }
}
